// Package opentelemetry
// Created by GoLand
// @User: lenora
// @Date: 2024/7/31
// @Time: 17:29

package opentelemetry

import (
	"camp/microbook/internal/service/sms"
	"context"
	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/trace"
)

type Decorator struct {
	svc    sms.Service
	tracer trace.Tracer
}

func NewDecorator(svc sms.Service, tracer trace.Tracer) *Decorator {
	return &Decorator{svc: svc, tracer: tracer}
}

func (d *Decorator) Send(ctx context.Context, tplId string, args []string, phone ...string) error {
	ctx, span := d.tracer.Start(ctx, "sms service")
	defer span.End()
	span.SetAttributes(attribute.String("tplId", tplId))
	err := d.svc.Send(ctx, tplId, args, phone...)
	if err != nil {
		span.RecordError(err)
	}
	return err
}
